#coding=utf-8
from elixir import *
from gui_session import gui_session

class Col(Entity):
    using_options(tablename='cols')
    
    name = Field(String(20), unique=True)
    col_head = Field(String(20), required=True)
    
    py_type = Field(String(20), required=True)
    gtk_type = Field(String(20), required=True)
    
    is_percent = Field(Boolean, default=False)
    is_colored = Field(Boolean, default=False)
    
    def __init__(self, n, h, pt, gt, ip=False, ic=False):

        self.name = n; self.col_head = h
        self.py_type = pt; self.gtk_type = gt
        self.is_percent = ip
        self.is_colored = ic

def find_col(name):
    return Col.query.filter_by(name = name).one()

if __name__ == '__main__':
    from stgui.guidb import *
    cols= [ Col('date', '交易日', 'str', 'gchararray'),
            
            Col('name', '名称', 'str', 'gchararray'),
            Col('code', '代码', 'str', 'gchararray'),
            
            Col('open', '开盘价', 'float', 'gdouble'),
            Col('close', '收盘价', 'float','gdouble'),
            Col('highest', '最高价', 'float', 'gdouble'),
            Col('lowest', '最低价', 'float', 'gdouble'),
            
            Col('change', '涨幅', 'float', 'gdouble', True, True),
            Col('jump', '跳空?', 'float', 'gdouble', True, True),
            
            Col('interval', '波动区间', 'str', 'gchararray'),
            Col('fluctuation', '波幅', 'float', 'gdouble', True),
            
            Col('volume', '成交量(股)', 'int', 'gint'),
            Col('amount', '成交额(元)', 'int', 'gint'),
            Col('trade_rate', '换手率', 'float', 'gdouble', True),
            Col('time', '时间', 'str', 'gchararray'),
            Col('now', '现价', 'float', 'gdouble')]
    
    gui_session.flush()
    
